<template>
	<!-- 商户的我的 -->
	<view class="wrapper">
		<!-- 个人资料 -->
		<view>
			<view class="top">
				<view class="center">
					<view class="center_top">
						<view class="center_img">
							<!-- 这里可以放自己的静态头像 -->
							<image src="/static/1.jpg"></image>
							<!--    <open-data type="userAvatarUrl" class="user_head"></open-data> -->
						</view>
						<view class="center_info">
							<view class="center_name">
								<!-- 这里可以放自己的名称图片 -->
								<view>{{usert.shopName}}</view>
							</view>
							<view class="center_vip">
								<image class="rank_icon" src="/static/b48c15b13d227807a10636722d3dcff.png" />
								<view class="vip_text">
									<text>{{usert.userName}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 其它 -->
		<view class="extra">
			<uni-list>
				<uni-list-item showArrow title="个人信息" @click="xinxi(usert.userId)" link="信息"></uni-list-item>
				<uni-list-item showArrow title="订单" @click="dingdan()" link="订单"></uni-list-item>
				<uni-list-item showArrow title="账单" @click="zhangdan()" link="账单"></uni-list-item>
				<uni-list-item showArrow title="审核提交" @click="tijiaoshenhe()" link="审核提交"></uni-list-item>
				<uni-list-item showArrow title="退出登录" @click="confirmLogout" link="退出登录"></uni-list-item>
			</uni-list>
		</view>
		<tabBar></tabBar>
	</view>
</template>
<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app"
	import {
		http
	} from '/until/request.js'
	// import { useInfoStore } from '../../store/user';
	// const tokenStore = useInfoStore()
	import {
		useTokenStore
	} from '../../../store/token';


	onLoad(() => {
		
		console.log("pinia中的用户对象")
		console.log(useTokenStore().token)
		xingxi()
	})
	onShow(() => {
		xingxi() // 每次页面显示时刷新用户信息
	});
	const usert = ref({})
	const xingxi = async () => {
		try {
			const uid = useTokenStore().token.uid;
			//从pinia中取出用户id
			const shuju = await http({
				url: '/audit/selectbyid/' + useTokenStore().token.uid,
				method: "get",
			});

			console.log("用户信息")
			console.log(shuju.data)

			usert.value = shuju.data;
			console.log(usert.value)

		} catch (error) {
			console.error('请求失败:', error);
		}
	}

	const zhangdan = () => {
		uni.navigateTo({
			url: "/pages/businessman/zhangdan/zhangdan?userId=" + usert.value.userId
		})
	}
	const tijiaoshenhe = async () => {
		const data = await http({
			url: '/audit/selectByuserId/' + useTokenStore().token.uid,
			method: 'get'
		});
		console.log(data)
		if (data.data == null) {
			// 显示提示信息
			uni.showToast({
			    title: '未审核即将跳转',
			    icon: 'loading',
			    duration: 2000 // 提示框显示的时间，单位是毫秒
			});
			
			// 设置定时器，在提示框显示结束后进行页面跳转
			setTimeout(function() {
			    uni.navigateTo({
			        url: "/pages/businessman/doorchuan/doorchuan?userId=" + useTokenStore().token.uid
			    });
			}, 2000);
		} else if(data.data.reviewStatus==1){
			uni.showToast({
				title:'审核已通过',
				icon:'success',
				duration:2000
			})
			console.log("-----------------")
					console.log(useTokenStore().token)
				const aa =  ref({});
				aa.uid = usert.value.userId;
				aa.reviewStatus = usert.value.reviewStatus
				useTokenStore().removeToken();
				useTokenStore().setToken(aa)
				console.log("-----------")
				console.log(usert.value)
				console.log(useTokenStore().token)
		}else if(data.data.reviewStatus==3){
			uni.showToast({
				title:'正在审核请稍后',
				icon:'loading',
				duration:2000
			})
		}else if(data.data.reviewStatus==2){
			uni.showToast({
				title:'审核未通过',
				icon:'error',
				duration:2000
			})
		}
	}

	const dingdan = (index) => {
		uni.navigateTo({
			url: "/pages/businessman/unpaid/unpaid"
		})
	}

	const xinxi = () => {
		console.log("个人信息id")
		console.log(usert.value.userId);
		uni.navigateTo({
			url: "/pages/businessman/index/gerenxinxi?userId=" + usert.value.userId
		})
	}


	// 确认退出登录的逻辑
	const confirmLogout = () => {
		uni.showModal({
			title: '确认退出',
			content: '您确定要退出登录吗？',
			confirmText: '退出',
			cancelText: '取消',
			success: (res) => {
				if (res.confirm) {
					// 显示加载动画
					uni.showLoading({
						title: '正在退出...',
					});

					try {
						// 清除本地存储的用户信息
						uni.clearStorageSync();

						// 隐藏加载提示
						uni.hideLoading();

						// 提示用户退出成功
						uni.showToast({
							title: '退出成功',
							icon: 'success',
							duration: 1500,
						});

						// 跳转到登录页面
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/pub/denglu1/denglu1'
							}); // 登录页面路径
						}, 1500);
					} catch (error) {
						console.error('退出操作失败:', error);

						// 隐藏加载提示
						uni.hideLoading();

						// 提示错误信息
						uni.showToast({
							title: '退出失败，请稍后再试',
							icon: 'none',
						});
					}
				} else {
					console.log('用户取消了退出操作');
				}
			},
		});
	};
</script>
<style lang="scss">
	.top {
		width: 100%;
		height: 230rpx;
		background: #2979ff;
		padding-top: 15px;
		position: relative;
	}

	.center {
		width: 95%;
		height: 200rpx;
		background: white;
		display: flex;
		flex-direction: column;
		margin: 0 auto;
		border-radius: 10rpx;
	}

	.center_top {
		display: flex;
		flex-direction: row;
		width: 80%;
		height: 160rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		border-bottom: 2rpx solid #EEEEEE;
	}

	.center_img {
		width: 142rpx;
		height: 142rpx;
		border-radius: 50%;
		overflow: hidden;
	}

	.center_img image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	.center_info {
		display: flex;
		flex-direction: column;
		margin-top: 20rpx;
		margin-left: 30px;
	}

	.center_name {
		font-size: 32rpx;
	}

	.center_phone {
		color: #BEBEBE;
	}

	.center_rank {
		width: 50%;
		height: 35rpx;
		display: flex;
		flex-direction: row;
	}

	.rank_text {
		height: 35rpx;
		line-height: 35rpx;
		margin-left: 10rpx;
		color: #AAAAAA;
	}

	.center_vip image {
		width: 45rpx;
		height: 45rpx;
		margin-top: 15rpx;
	}

	.vip_icon {
		width: 50rpx;
		height: 50rpx;
		margin-top: -10rpx;
	}

	.vip_text {
		margin-top: -55rpx;
		margin-left: 50rpx;
		color: #AAAAAA;
	}

	.center_rank image {
		width: 50rpx;
		height: 50rpx;
	}

	.center_score {
		width: 50%;
		height: 35rpx;
		display: flex;
		flex-direction: row;
	}

	.center_score image {
		width: 35rpx;
		height: 35rpx;
	}

	.gif-wave {
		position: absolute;
		width: 100%;
		bottom: 0;
		left: 0;
		z-index: 99;
		mix-blend-mode: screen;
		height: 100rpx;
	}

	.wrapper {
		position: absolute;
		top: 0;
		bottom: 0;
		width: 100%;
		background-color: #F4F4F4;
	}

	.profile {
		height: 375rpx;
		background-color: #ea4451;
		display: flex;
		justify-content: center;
		align-items: center;

		.meta {
			.avatar {
				display: block;
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
				border: 2rpx solid #fff;
				overflow: hidden;
			}

			.nickname {
				display: block;
				text-align: center;
				margin-top: 20rpx;
				font-size: 30rpx;
				color: #fff;
			}
		}
	}

	.count {
		display: flex;
		margin: 0 20rpx;
		height: 120rpx;
		text-align: center;
		border-radius: 4rpx;
		background-color: #fff;
		position: relative;
		top: 10rpx;

		.cell {
			margin-top: 10rpx;
			flex: 1;
			padding-top: 20rpx;
			font-size: 27rpx;
			color: #333;
		}

		text {
			display: block;
			font-size: 24rpx;
		}
	}

	.orders {
		margin: 20rpx 20rpx 0 20rpx;
		padding: 40rpx 0;
		background-color: #fff;
		border-radius: 4rpx;

		.title {
			padding-left: 20rpx;
			font-size: 30rpx;
			color: #333;
			padding-bottom: 20rpx;
			border-bottom: 1rpx solid #eee;
			margin-top: -30rpx;
		}

		.sorts {
			padding-top: 30rpx;
			text-align: center;
			display: flex;
		}

		[class*="icon-"] {
			flex: 1;
			font-size: 24rpx;

			&::before {
				display: block;
				font-size: 48rpx;
				margin-bottom: 8rpx;
				color: #ea4451;
			}
		}
	}

	.address {
		line-height: 1;
		background-color: #fff;
		font-size: 30rpx;
		padding: 25rpx 0 25rpx 20rpx;
		margin: 10rpx 20rpx;
		color: #333;
		border-radius: 4rpx;
	}

	.extra {
		margin: 10rpx 20rpx;
		background-color: #fff;
		border-radius: 4rpx;

		.item {
			line-height: 1;
			padding: 25rpx 0 25rpx 20rpx;
			border-bottom: 1rpx solid #eee;
			font-size: 30rpx;
			color: #333;
		}

		button {
			text-align: left;
			background-color: #fff;

			&::after {
				border: none;
				border-radius: 0;
			}
		}
	}

	.icon-arrow {
		position: relative;

		&::before {
			position: absolute;
			top: 50%;
			right: 20rpx;
			transform: translateY(-50%);
		}
	}
</style>